<html>
<head>
    <title>Hello World</title>
</head>
<body>
<?php

require_once ('/var/www/peachy/Init.php');

function addKeyvalue ( &$editarray) 
{
    $editarray['section'] = 1;
}

$wiki = Peachy::newWiki ("ini");
$page = $wiki -> initPage ( $_POST['title'] );

$text = "=Details=\n";

$array_project = explode ( ",", $_POST['keys_project'] );
$array_experiment =  explode (",", $_POST['keys_experiment'] );
$array_mpid =  explode (",", $_POST['keys_mpid'] );
$array_thumbnail = explode (",", $_POST['keys_thumbnail'] );
$array_bigImage = explode (",", $_POST['keys_bigImage'] );

$text .= "\n{|border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\"\n" ;
$text .= "!colspan=\"3\" | Images (click on the image to explore more) \n";

$count = 0;
foreach ( $array_thumbnail as $x )
{
   if ( $count == 0) { 
      $text .= "|-\n";
      $count = 3;
   }
   $text .= "| [". $_POST[$x."_bigImage"]. " " .$_POST[$x."_thumbnail"] . "] \n";
   
   $count --;
}

$text .= "|}\n\n";

$text .= "\n\n{|border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" \n" ;
$text .= "!colspan=\"2\" | Project \n";

foreach ( $array_project as $x )
{
   $text .= "|-\n";
   $text .= "|$x \n";
   $text .= "|". $_POST[$x."_project"]."\n";
}

$text .= "|}\n\n";

$text .= "\n\n{|border=\"1\" cellspacing=\"1\" width=\"100%\" cellpadding=\"4\"\n" ;
$text .= "!colspan=\"2\" | Experiment \n";

foreach ( $array_experiment as $x )
{
   $text .= "|-\n";
   $text .= "|$x \n";
   $text .= "|". $_POST[$x."_experiment"]."\n";
}

$text .= "|}\n\n";

$text .= "\n\n{|border=\"1\" cellspacing=\"1\" width=\"100%\" cellpadding=\"4\"\n" ;
$text .= "!colspan=\"2\" | MPID \n";

foreach ( $array_mpid as $x )
{
   $text .= "|-\n";
   $text .= "|$x \n";
   $text .= "|". $_POST[$x."_mpid"]."\n";
}

$text .= "|}\n\n";

$commentText = $page -> get_text( false, 2);

if ( $commentText  == '' ) {
   $text .= "\n=Comments=\n";
}
else {
   $text .= "\n" . $commentText;
}

//$pgHooks['StartEdit'][] = 'addKeyValue';

$page -> edit ( $text, "Testing paging");

?>

</body>
</html>
